﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;
using LuKou.Shopspace.Domains;

namespace LuKou.Web.Form
{
    public class GoodsForm
    {
        [DisplayName("商品ID")]
        public long GoodsID { get; set; }

        [Required(ErrorMessage = "分类为空")]
        [DisplayName("商品分类")]
        public long CategoryID { get; set; }

        [Required(ErrorMessage = "不能为空")]
        [DisplayName("商品名称")]
        public string Name { get; set; }

        [DisplayName("商品品牌:")]
        public string Brand { get; set; }

        [DisplayName("标签")]
        public string Tags { get; set; }

        [DisplayName("价格")]
        [Required(ErrorMessage = "不能为空")]
        public float Price { get; set; }

        [DisplayName("库存")]
        public int Stock { get; set; }

        [DisplayName("货号")]
        [Required(ErrorMessage = "不能为空")]
        public string SUK { get; set; }

        [DisplayName("是否上架")]
        public bool IsShow { get; set; }

        [DisplayName("是否推荐")]
        public bool Recommended { get; set; }

        [DisplayName("会员下载数据包等级")]
        [Required(ErrorMessage = "不能为空")]
        public int DownLevel { get; set; }

        [DisplayName("商品描述")]
        public string Description { get; set; }

        public string[] MajorImages { get; set; }

        public string[] Images { get; set; }

        /// <summary>
        /// 商品的淘宝属性
        /// </summary>
        public List<TbAttr> TbAttr { get; set; }

        /// <summary>
        /// 商品SKU属性
        /// </summary>
        public List<TbSkuAttr> GoodsSku { get; set; }
    }

    public class TbAttr
    {
        public int Pid{get;set;}

        public string[] Vid{get;set;}
    }

    public class TbSkuAttr
    {
        public decimal Price { get; set; }

        public int Amount { get; set; }

        public string OuterNum { get; set; }

        public string[] Code { get; set; }

        public List<GoodsSKUProp> GetSkuProps()
        {
            List<GoodsSKUProp> prop = new List<GoodsSKUProp>();
            if (Code!=null && Code.Length>0)
            {
                prop.AddRange(from str in Code.Select(s => s.Split('|')) 
                              where str.Length == 2 
                              select new GoodsSKUProp() {Pid = Convert.ToInt64(str[0]), Vid = Convert.ToInt64(str[1])});
            }

            return prop;
        }
    }
}
